From 98be36a5f6e49fd2e0434890e08230b5f008e553 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Wed, 22 Jul 2026 23:13:51 +0000 Subject: [PATCH] Allow PANTGRUNTS_VIEW to be updated and deleted --- .../lib/triggers/create/pantgrunts_view.m4 | 73 ++++++++++++++++++- doc/src/views/pantgrunts_view.m4 | 13 +++- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/db/schemas/lib/triggers/create/pantgrunts_view.m4 b/db/schemas/lib/triggers/create/pantgrunts_view.m4 index 72d6742..013aa2c 100644 --- a/db/schemas/lib/triggers/create/pantgrunts_view.m4 +++ b/db/schemas/lib/triggers/create/pantgrunts_view.m4 @@ -41,7 +41,7 @@ CREATE OR REPLACE FUNCTION pantgrunts_view_insert_func () target_notes watches.notes%TYPE; target_eid events.eid%TYPE; - target_behavior events.behavior%TYPE; + target_time events.start%TYPE; target_event_notes events.notes%TYPE; @@ -135,6 +135,73 @@ CREATE OR REPLACE FUNCTION pantgrunts_view_insert_func () $$; +RAISE INFO 'pantgrunts_view_update_func'; +CREATE OR REPLACE FUNCTION pantgrunts_view_update_func () + RETURNS trigger + LANGUAGE plpgsql + sdb_function_set_search_path + AS $$ + BEGIN + -- Function for pantgrunts_view instead of update trigger + -- + -- AGPL_notice(` --', `2026', + `The Meme Factory, Inc., www.karlpinc.com') + + UPDATE pantgrunts + SET eid = NEW.eid + , multiactors = NEW.multiactors + , multirecipients = NEW.multirecipients + , commid = NEW.commid + , source = NEW.source + , enteredby = NEW.enteredby + WHERE pantgrunts.eid = OLD.eid; + + UPDATE dyads + SET wid = NEW.wid + , date = NEW.date + , animid = NEW.animid + , type = NEW.type + , commid = NEW.commid + , eid = NEW.eid + , start = NEW.time + , stop = NEW.time + , actor_pid = NEW.actor_pid + , actor = NEW.actor + , recipient_pid = NEW.recipient_pid + , recipient = NEW.recipient + , style = NEW.style + , notes = NEW.notes + , event_notes = NEW.event_notes + WHERE eid = OLD.eid; + + RETURN NEW; + END; +$$; + + +RAISE INFO 'pantgrunts_view_delete_func'; +CREATE OR REPLACE FUNCTION pantgrunts_view_delete_func () + RETURNS trigger + LANGUAGE plpgsql + sdb_function_set_search_path + AS $$ + BEGIN + -- Function for pantgrunts_view instead of delete trigger + -- + -- AGPL_notice(` --', `2026', + `The Meme Factory, Inc., www.karlpinc.com') + + DELETE FROM pantgrunts + WHERE pantgrunts.eid = OLD.eid; + + DELETE FROM dyads + WHERE dyads.eid = OLD.eid; + + RETURN OLD; + END; +$$; + + CREATE TRIGGER pantgrunts_view_insert_trigger INSTEAD OF INSERT ON pantgrunts_view FOR EACH ROW @@ -143,9 +210,9 @@ CREATE TRIGGER pantgrunts_view_insert_trigger CREATE TRIGGER pantgrunts_view_update_trigger INSTEAD OF UPDATE ON pantgrunts_view FOR EACH ROW - EXECUTE PROCEDURE _error_immutable_view(); + EXECUTE PROCEDURE pantgrunts_view_update_func(); CREATE TRIGGER pantgrunts_view_delete_trigger INSTEAD OF DELETE ON pantgrunts_view FOR EACH ROW - EXECUTE PROCEDURE _error_immutable_view(); + EXECUTE PROCEDURE pantgrunts_view_delete_func(); diff --git a/doc/src/views/pantgrunts_view.m4 b/doc/src/views/pantgrunts_view.m4 index 03f4595..52ab72d 100644 --- a/doc/src/views/pantgrunts_view.m4 +++ b/doc/src/views/pantgrunts_view.m4 @@ -179,7 +179,16 @@ INSERT the values already existing in, or inserted into, the database. UPDATE - This operation is not allowed. + UPDATEing the PANTGRUNTS_VIEW view updates the underlying tables, + as expected. DELETE - This operation is not allowed. + DELETEing rows from the PANTGRUNTS_VIEW view deletes rows from the + underlying tables. + + Rows are always deleted from |PANTGRUNTS| and |ROLES|, and may be + deleted from |EVENTS| and |WATCHES| as well. + + The process of deleting rows from |ROLES|, |EVENTS|, and |WATCHES| + is delegated to the |DYADS| view. + See the documentation of the |DYADS| view for further detail. -- 2.34.1